package com.zyf.chapter01.principle.SOLID.DIP.DI.optimization;

/**
 * 依赖注入实现方式
 * 使用 Notification
 * MessageSender messageSender = new SmsSender();
 * Notification Notification = new Notification(messageSender);
 * @author yifeng
 */
public class Notification {
    private MessageSender messageSender;

    // 通过构造函数将 messageSender 传递进来
    public Notification(MessageSender messageSender) {
        this.messageSender = messageSender;
    }

    public void sendMessage(String cellphone, String message) {
        // ... 省略校验逻辑等 ...
        this.messageSender.send(cellphone, message);
    }
}
